/**
 * geoportal-gm-settings.js
 * This javascript contains map and layer parameters and global variables to support map-gm.js.
 * 
 * @author 		Tobin Bradley
 * @license 	MIT
 */

var map;
var markers = [];
var markerIcons = [{icon: ''}, {icon: 'img/blue-marker.png'}, {icon: 'img/dd-start.png'}]; // selected address, other stuff
var shadow = new google.maps.MarkerImage('img/shadow50.png', new google.maps.Size(37, 34), new google.maps.Point(0,0), new google.maps.Point(10, 34));
var selectedAddress = null;
var zoomPrevious = [];
var zoomNext = [];
var panListener;
var zoomListener;
var clickListener;
var gpsWatch;

/* Measure Variables */
var markerImageDefault = new google.maps.MarkerImage('img/measure-vertex.png',null, null, new google.maps.Point(5,5));
var markerImageHover = new google.maps.MarkerImage('img/measure-vertex-hover.png',null, null, new google.maps.Point(8,8));
var measure = {
    ll:new google.maps.MVCArray(),
    ll2:new google.maps.MVCArray(),
    markers:[],
    line:null,
    poly:null
}

/* parameters for mecklenburg base layers and services */
var wsbase = "http://maps.co.mecklenburg.nc.us/rest/";   // Base URL for REST web services
var meckWMSBase = "http://maps.co.mecklenburg.nc.us/geoserver/wms?";
var meckWMSParams = [
	 "REQUEST=GetMap",
	 "SERVICE=WMS",
	 "VERSION=1.1.1",
	 "BGCOLOR=0xFFFFFF",
	 "TRANSPARENT=TRUE",
	 "SRS=EPSG:900913", // 3395? 
	 "WIDTH=256",
	 "HEIGHT=256"
];



/**
 * Map options
 */
var myOptions = {
	zoom: 8,
	center: new google.maps.LatLng(35.270, -80.837),
	mapTypeId: google.maps.MapTypeId.ROADMAP,
	scaleControl: true,
	maxZoom: 18,
	minZoom: 10
};
	 

/**
 * Base maps
 */
var baseMaps = [
	 {
		  name: "Meck Base",
		  alt: "Meck Base Map",
		  getTileUrl: function(ll, z) {
			   var X = ll.x % (1 << z);  // wrap
			   return 'http://maps.co.mecklenburg.nc.us/geoserver/gwc/service/gmaps?layers=meckbase&zoom=' + z + '&x=' + X + '&y=' + ll.y + '&format=image/png';
		   },
		   tileSize: new google.maps.Size(256, 256),
		   isPng: true,
		   maxZoom: 18
	 },{
		  name: "OSM",
		  alt: "Open Streetmap tiles",
		  getTileUrl: function(ll, z) {
			   var X = ll.x % (1 << z);  // wrap
			   return "http://tile.openstreetmap.org/" + z + "/" + X + "/" + ll.y + ".png";
		  },
		  tileSize: new google.maps.Size(256, 256),
		  isPng: true,
		  maxZoom: 18
	 }
];



/**
 * Overlay Maps
 */
var overlayMaps = [
	 {
		  name: "Environmental Layers",
		  getTileUrl: function(coord, zoom) {
			   var layerParams = [
					"FORMAT=image/png8",
					"LAYERS=postgis:view_regulated_floodplains,postgis:landfills,postgis:mpl_sites,postgis:water_quality_buffers,postgis:proposed_thoroughfares,postgis:soil,postgis:air_pollution_facilities",
					"STYLES="
			   ];
			   return WMSBBOXUrl(meckWMSBase + meckWMSParams.concat(layerParams).join("&"), coord, zoom, 15, 18); 
		  },  
		  tileSize: new google.maps.Size(256, 256),  
		  opacity: 0.6,
		  isPng: true,
		  minZoom: 15,
		  maxZoom: 18
	 },{
		  name: "Nexrad Weather Radar",
		  getTileUrl: function(coord, zoom) {            
			   return WMSBBOXUrl("http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&BGCOLOR=0xFFFFFF&TRANSPARENT=TRUE&SRS=EPSG:900913&WIDTH=256&HEIGHT=256&FORMAT=image/png&LAYERS=nexrad-n0r", coord, zoom, 9, 18); 
		  },  
		  tileSize: new google.maps.Size(256, 256),  
		  opacity: 0.6,
		  isPng: true,
		  minZoom: 9,
		  maxZoom: 18
	 },{
		  name: "Tax Parcels",
		  getTileUrl: function(coord,zoom){
			   if (map.getZoom() >= 15 && map.getZoom() <= 18) {
					return 'http://maps.co.mecklenburg.nc.us/geoserver/gwc/service/gmaps?layers=postgis%3Atax_parcels&zoom=' + zoom + '&x=' + coord.x + '&y=' + coord.y + '&format=image/png';
			   }
			   else return false; 
		  },
		  tileSize: new google.maps.Size(256,256),
		  isPng:true,
		  minZoom: 15,
		  maxZoom: 18
	 }
];

// These layers will be automatically loaded but not shown in the layer switcher
var autoOverlayMaps = ["Tax Parcels"]; 

